<template>
  <div v-loading="loading">
    <a-form-model
      ref="transferForm"
      :rules="rules"
      :model="transferInfo"
      :labelCol="{ span: 4 }"
      :wrapperCol="{ span: 10 }"
    >
      <a-form-model-item label="让利比例(%)" prop="transfer_profit">
        <a-input-number
          :min="0"
          :max="100"
          :step="0.1"
          precision="2"
          v-model="transferInfo.transfer_profit"
          style="width: 100%"
        />
        <!-- <div class='max_price_tips'>最高：{{transferInfo.max_price}}</div> -->
      </a-form-model-item>

      <!-- <a-form-model-item label="修改联盟券数额" prop="league_price">
        <a-input-number
          :min="0"
          :step="0.01"
          precision="2"
          v-model="transferInfo.league_price"
          style="width: 100%"
        />
      </a-form-model-item> -->

      <a-form-model-item :wrapper-col="{ span: 24 }">
        <a-divider style="margin:0 0 40px 0;"/>
        <div style="display: flex; justify-content: center;">
          <a-button :loading="btnLoading" type="primary" @click="submitForm" style="margin-right: 8px"> 保存 </a-button>
          <a-button @click="$router.back()"> 取消 </a-button>
        </div>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
import { getTransferProfitParams, setTransferProfitParams } from '@/api/store'

export default {
  name: 'SaasSettingReferral',
  data() {
    return {
      loading: false,
      btnLoading: false,
      transferInfo: {
        transfer_profit: 0.0,
        league_price:0.0,
      },
      rules: {
        transfer_profit: [{ required: true, message: '请输入商城让利比例', trigger: 'blur' }],
      },
    }
  },
  created() {
    this.getData()
  },
  props: {
    storeId: {
      type: Number,
      default: 0,
    },
  },
  methods: {
    getData: function () {
      this.loading = true
      getTransferProfitParams({ storeId: this.storeId })
        .then((res) => {
          if (res.code == 0) {
            this.transferInfo = res.data
          }
        })
        .catch((error) => {
          console.log(error)
        })
        .then(() => {
          this.loading = false
        })
    },
    submitForm: function () {
      this.$refs.transferForm.validate((valid) => {
        if (valid) {
          this.btnLoading = true
          setTransferProfitParams({
            ...this.transferInfo,
            storeId: this.storeId,
          })
            .then((res) => {
              if (res.code == 0) {
                this.$message.success('保存成功！')
              } else {
                this.$message.warning(res.msg ? res.msg : '保存失败！')
              }
            })
            .catch((error) => {
              console.log(error)
            })
            .then(() => {
              this.btnLoading = false
            })
        }
      })
    },
  },
}
</script>

<style scoped>
.max_price_tips {
  color: #f00;
}
</style>
